package cn.gjculture.shopping.api.dao;

import cn.gjculture.shopping.api.entity.Commodity;
import cn.gjculture.shopping.api.entity.Goods;
import cn.gjculture.shopping.api.entity.GoodsMapPostageTemplate;
import cn.gjculture.shopping.api.entity.Supplier;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface VipGoodsDao {


    @Insert("insert into vipgoods(goodsId,goodsNo,goodsTypeId,goodsName,goodsDesc,updateTime,insertTime,goodsIntroduction,status,inventory,unit," +
            "discount,price,discountPrice,supplierId,brandId,recommended,superDiscount,`index`,sales,activityType,primeCost) values(#{goodsId},#{goodsNo},#{goodsTypeId},#{goodsName},#{goodsDesc},#{updateTime},#{insertTime}," +
            "#{goodsIntroduction},#{status},#{inventory},#{unit},#{discount},#{price},#{discountPrice},#{supplierId},#{brandId},#{recommended},#{superDiscount},#{index},#{sales},#{activityType},#{primeCost})")
    Integer insert(Goods goods);

    @Select("select * from vipgoods where goodsId=#{goodsId}")
    Goods queryById(String goodsId);

    @Select("select t1.*, sum(t2.count) as count from vipgoods t1 LEFT join goodsrecord t2 on t1.goodsId=t2.goodsid group by t1.goodsId order by `index`")
    List<Goods> query();

    @Delete("delete from vipgoods where goodsId=#{id}")
    Integer delete(String id);

    @Select("select goodsStand from goodsstand where goodsId=#{goodsId}")
    List<String> queryStands(String goodsId);

    @Select("select goodsColor from goodscolors where goodsId=#{goodsId}")
    List<String> queryColors(String goodsId);

    @Delete("delete from goodscolors where goodsId=#{goodsId}")
    Integer deleteColor(String goodsId);

    @Delete("delete from goodsstand where goodsId=#{goodsId}")
    Integer deleteStand(String goodsId);

    @Select("select * from vipgoods order by insertTime")
    Page<Goods> queryForPage();

    @Select("select * from thumbnail where goodsId=#{goodsId}")
    List<Commodity.Thumbnail> queryThumb(String goodsId);

    @Select("delete from thumbnail where goodsId=#{goodsId}")
    Integer deleteThembnail(String goodsId);

    @Select("select * from vipgoods where goodsTypeId=#{goodsTypeId}")
    List<Goods> queryByTypeId(String goodsTypeId);

    @Update("update vipgoods set recommended=#{recommended} where goodsId=#{goodsId}")
    Integer recommended(Goods goods);
    @Select("select * from vipgoods where recommended=0 order by `index`")
    List<Goods> queryRecommended();

    @Update("update vipgoods set status=#{status} where goodsId=#{goodsId}")
    int updateStatus(Goods goods);
    @Select("select count(1) from goods where brandId=#{brandId} ")
    Integer queryByBrandId(String brandId);

    @Select("select * from vipgoods where activityType=#{activityType} order by `index`")
    List<Goods> queryByActivityType(Integer activityType);
    @Select("select t1.* from supplier t1  RIGHT JOIN vipgoods t2 on t1.supplierId=t2.supplierId where t2.goodsId=#{goodsId}")
    Supplier querySupplierByGoodsId(String goodsId);

    @Delete("delete from goodsmappostagetemplate where goodsId=#{goodsId} and postageTemplateId=#{postageTemplateId}")
    int deletePostageTemplate(GoodsMapPostageTemplate template);
}
